<?php
session_start();
include("load-settings.php");

if(!isset($_SESSION['user']))
	header("Location: login.php");

$user = mysql_real_escape_string($_SESSION['user']);
$result = mysql_query("SELECT * FROM user WHERE id = $user");
$row = mysql_fetch_array($result);

if($row['type'] != 2)
	header("Location: home.php");
?>
<!doctype html>
<html>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1, user-scalable=0">

  <!-- Always force latest IE rendering engine or request Chrome Frame -->
  <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<link rel="icon" href="http://veteranboosters.com/orders/images/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="http://veteranboosters.com/orders/images/favicon.ico" type="image/x-icon"/>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,800">

  <!-- Use title if it's in the page YAML frontmatter -->
  <title>ELO Edge Order Tracking</title>


  <!--[if lt IE 9]>
  <script src="../../javascripts/vendor/html5shiv.js" type="text/javascript"></script>
  <script src="../../javascripts/vendor/excanvas.js" type="text/javascript"></script>
  <![endif]-->

  <link href="stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
  <script src="javascripts/application.js" type="text/javascript"></script>
</head>

<?php
	include("top.php");
?>

  <div class="container-fluid padded">
    <div class="row-fluid">

      <!-- Breadcrumb line -->

      <div id="breadcrumbs">
               <div class="breadcrumb-button blue">
                  <span class="breadcrumb-label"><i class="icon-home"></i> Home</span>
                  <span class="breadcrumb-arrow"><span></span></span>
               </div>

               <div class="breadcrumb-button">
                  <span class="breadcrumb-label">
                     <i class="icon-user"></i> Members
                  </span>
                  <span class="breadcrumb-arrow"><span></span></span>
               </div>
               
               <div class="breadcrumb-button">
                  <span class="breadcrumb-label">
                     <i class="icon-reorder"></i> Accounts                  </span>
                  <span class="breadcrumb-arrow"><span></span></span>
               </div>
            </div>
    </div>
  </div>

  <div class="container-fluid padded">
  <div class="row-fluid">
   <!--<div class="span6">
      <div class="box">
         <div class="box-header">
            <span class="title">Add new accounts</span>
         </div>
         <div class="box-content">
            <table class="table table-normal">
               <thead>
                  <tr>
					 <td>Accounts</td>
					 <td>Region</td>
					 <td>Actions</td>
                  </tr>
               </thead>
               <tbody>
			      <form action = "add-bulk-accounts.php" method = "post">
                  <tr><td style = "width: 80%;"><textarea name = "accounts" style = "height: 400px; width: 100%"></textarea></td>
				  <td>
					<select name = "region" style = "margin: 0px; width: auto;">
						<option value = "na">North America</option>
						<option value = "euw">Europe West</option>
						<option value = "eune">Europe East</option>
					</select>
				  </td>
				  <td>
					<input type="submit" class="btn btn-info" value="Create">
				  </td>
				  </tr>
				  </form>
			   </tbody>
            </table>
         </div>
      </div>
   </div>-->
   <div class="span12">
      <div class="box">
         <div class="box-header">
            <span class="title">Unused accounts</span>
         </div>
         <div class="box-content">
            <table class="table table-normal">
               <thead>
                  <tr>
					 <td>Accounts</td>
					 <td>Referrals</td>
					 <td>Region</td>
					 <td>Actions</td>
                  </tr>
               </thead>
               <tbody>
			      <form action = "update-bulk-accounts.php" method = "post">
                  <tr><td style = "width: 80%;"><textarea id = "accounts" name = "accounts" style = "height: 400px; width: 100%"><?php
						$result = mysql_query("SELECT * FROM bulk_account WHERE region = 'na' AND used = 0 AND referrals = 0");

						while($row = mysql_fetch_array($result))
						{
							echo $row['username'].":".$row['password']."\n";
						}
				  ?></textarea></td>
				  <td>
					<select name = "referrals" id = "referrals" style = "margin: 0px; width: auto;" onchange = "get_region()">
						<option value = "0">0</option>
						<option value = "50">50</option>
						<option value = "100">100</option>
					</select>
				  </td>
				  <td>
					<select name = "region" id = "region" style = "margin: 0px; width: auto;" onchange = "get_region()">
						<option value = "na">North America</option>
						<option value = "euw">Europe West</option>
						<option value = "eune">Europe East</option>
						<option value = "oce">Oceania</option>
					</select>
				  </td>
				  <td>
					<input type="submit" class="btn btn-info" value="Update">
				  </td></tr>
				  </form>
			   </tbody>
            </table>
         </div>
      </div>
   </div>
</div>
</div>
<script>
function get_region ()
{
	var region = document.getElementById("region").value;
	var referrals = document.getElementById("referrals").value;

	var ajaxHandler = new XMLHttpRequest();

	ajaxHandler.onreadystatechange = function ()
	{
		if(ajaxHandler.readyState == 4)
		{
			document.getElementById("accounts").innerHTML = ajaxHandler.responseText;
		}
	}

	var form = new FormData();
	form.append("region", region);
	form.append("referrals", referrals);

	ajaxHandler.open("POST", "get-bulk-accounts.php", true);
	ajaxHandler.send(form);
}
</script>
<?php
	include("bottom.php");
?>